package com.ssh.admin.action;

import java.util.Map;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.apache.struts2.interceptor.SessionAware;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;
import com.ssh.common.util.JsonResult;
import com.ssh.entity.Admin;
import com.ssh.manager.AdminManager;

@Controller
@ParentPackage("admin")
@Scope("prototype")
@Results(value={
@Result(name="success", location="/admin/adminMain.jsp"),
@Result(name="error", location="/admin/login/login.jsp")		
})
/*@Results(value={
		@Result(name="adminLogin", type="json", params={"root","jr","excludeproperties",
				"code,method,data\\[\\d+\\]\\.id,data\\[\\d+\\]\\.userName,data\\[\\d+\\]\\.password,data\\[\\d+\\]\\.createDate","excludeNullProperties","true"})
})*/
public class AdminAction extends ActionSupport implements SessionAware{
	@Resource(name="adminManagerImpl")
	private AdminManager adminManager;
	
	private Admin admin;
	private JsonResult jr=new JsonResult();
	private Map session;
	
	public Map getSession() {
		return session;
	}

	public void setSession(Map session) {
		this.session = session;
	}

	public JsonResult getJr() {
		return jr;
	}

	public void setJr(JsonResult jr) {
		this.jr = jr;
	}

	public Admin getAdmin() {
		return admin;
	}

	public void setAdmin(Admin admin) {
		this.admin = admin;
	}

	//用户登陆方法
	public String adminLogin() throws Exception{
		admin = adminManager.adminLogin(admin.getUserName(), admin.getPassword());
		if (admin!=null) {
			session.put("admin", admin);
			return "success";
		}else {
			return "error";
		}
	}
	
	public String loginExport() throws Exception{
		session.remove("admin");
		return "error";
	}
}
